﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using BLL;
public partial class admin_志愿者管理_审核志愿者申请书 : BLL.BasePage_Admin
{
    Volunteer_Apply bll_Volunteer_Apply = new Volunteer_Apply();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            UIInit();
        }
    }

    private void UIInit()
    {
        Bind_GridView();
        Set_PagingCount();
    }

    private void Set_PagingCount()
    {
        AspNetPager1.RecordCount = bll_Volunteer_Apply.GetRecordCount(GetWhere());
    }

    private void Bind_GridView()
    {
        DataTable dt = bll_Volunteer_Apply.GetListByPage(GetWhere(), "InsTime desc", AspNetPager1.StartRecordIndex, AspNetPager1.EndRecordIndex + AspNetPager1.PageSize).Tables[0];
        dt.Columns.Add("District");
        dt.Columns.Add("DisposeStatus");
        Helper_District helper_District = new Helper_District();
        foreach (DataRow dr in dt.Rows)
        {
            dr["District"] = helper_District.Get_FullPath_DistrictId(Convert.ToInt32(dr["DistrictId"]),Helper_District.ShowType.无符号连接);
            dr["DisposeStatus"] = Get_DisposeStatus(dr);
        }
        GridView1.DataSource = dt;
        GridView1.DataBind();
        lblPagingInfo.Text = PublicControlBind.GetPagingInfo(dt.Rows.Count, (AspNetPager1.StartRecordIndex - 1) / AspNetPager1.PageSize + 1, AspNetPager1.PageSize);
    }

    private string Get_DisposeStatus(DataRow dr)
    {
        bool isReject = Convert.ToBoolean(dr["isReject"]);
        bool isPass = Convert.ToBoolean(dr["isPass"]);
        string result = string.Empty;
        if (isReject)
        {
            result = "<span style=\"color:blue\">已拒绝</span>";
        }
        else if (isPass)
        {
            result = "<span style=\"color:green\">已通过</span>";
        }
        else
        {
            result = "<span style=\"color:red\">未处理</span>";
        }
        
        return result;
    }
    /// <summary>
    /// 拼装where
    /// </summary>
    /// <returns></returns>
    private string GetWhere()
    {
        string where = "1=1";
        where += GetWhere_Date(txtFromDate.Text, txtToDate.Text, "InsTime");
        where += GetWhere_Str_Like(txtName.Text.Trim(),"name");
        where += GetWhere_List(ddlType.SelectedValue, "sex");
        return where;
    }

    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
        bll_Volunteer_Apply.Delete(id);
        Bind_GridView();
        Set_PagingCount();
    }
    /// <summary>
    /// 分页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        Bind_GridView();
    }
    /// <summary>
    /// 搜索
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        if (!Check_Date(txtFromDate.Text,txtToDate.Text))
        {
            return;
        }
        Bind_GridView();
        Set_PagingCount();
    }
}
